import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departmentsAsuncRoute from './modules/departments'
import employeesAsuncRoute from './modules/employees'
import settingsAsuncRoute from './modules/settings'
import salarysAsuncRoute from './modules/salarys'
import socialSecuritysAsuncRoute from './modules/social_securitys'
import attendancesAsuncRoute from './modules/attendances'
import approvalsAsuncRoute from './modules/approvals'
import permissionsAsuncRoute from './modules/permissions'

// 创建动态路由表
export const asyncRouter = [
  departmentsAsuncRoute,
  employeesAsuncRoute,
  settingsAsuncRoute,
  salarysAsuncRoute,
  socialSecuritysAsuncRoute,
  attendancesAsuncRoute,
  approvalsAsuncRoute,
  permissionsAsuncRoute

]

// 静态路由表
export const constantRoutes = [
  {
    path: '/import',
    component: () => import(/* webpackChunkName:"import"*/'@/views/import/index.vue'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName:"login"*/'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName:"404"*/'@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName:"Dashboard"*/'@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes] // 最终生成动态路由表（静态和动态组成）
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
